package com.aabte.permissionframeworklearn.permission.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;

/**
 * @author Daniel
 */
@Slf4j
@Service
public class RedisPool {

    @Autowired
    private ShardedJedisPool shardedJedisPool;

    public ShardedJedis instance() {
        return shardedJedisPool.getResource();
    }

    public void safeClose(ShardedJedis resource) {
        try {
            if (null != resource) {
                resource.close();
            }
        } catch (Exception e) {
            log.error("return redis resource exception.", e);
        }
    }

}
